<?php
namespace app\admin\controller;
use app\admin\model\IndexTableModel;
use app\admin\model\JoinTableModel;
use app\admin\model\RyImLogic;
use think\Db;
use think\Request;
use app\common\model\User;
use app\common\model\UserLevel;
use app\common\validate\UserValidate;

require_once (__DIR__.'/../../../vendor/ReidsLock.class.php');
class FamemberController extends Controller
{

    /**
     * 用户列表
     * User:@hang
     */
    public function index(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['a.member_id','=',$param['member_id']];
        }
        if (isset($param['me_uid']) && !empty($param['me_uid'])) {
            $whehe[] = ['a.me_uid','like',"%{$param['me_uid']}%"];
        }
        if (isset($param['me_phone']) && !empty($param['me_phone'])) {
            $whehe[] = ['a.me_phone','like',"%{$param['me_phone']}%"];
        }
        if (isset($param['me_nick_name']) && !empty($param['me_nick_name'])) {
            $whehe[] = ['a.me_nick_name','like',"%{$param['me_nick_name']}%"];
        }
        if (isset($param['s_member_id']) && !empty($param['s_member_id'])) {
            $whehe[] = ['a.me_parent','=',$param['s_member_id']];
        }
        $whehetime = '';
        if (isset($param['me_add_time']) && !empty($param['me_add_time'])) {
            $time_arr = explode(' - ', $param['me_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetime = "a.me_add_time >= $start_time AND a.me_add_time <= $end_time";
        }
        if (isset($param['me_status']) && !empty($param['me_status'])) {
            switch($param['me_status']){
                case '1': $whehe[] = ['a.me_status','=',$param['me_status']];break;
                case '2': $whehe[] = ['a.me_status','=',$param['me_status']];$whehe[] = ['a.me_zhuxiao','neq',1];break;
                case '3': $whehe[] = ['a.me_zhuxiao','=',1];break;
            }
        }
        if (isset($param['me_sex']) && $param['me_sex'] != '') {
            $whehe[] = ['a.me_sex','=',$param['me_sex']];
        }
        if (isset($param['me_zx']) && $param['me_zx'] != '') {
            $whehe[] = ['a.me_zx','=',$param['me_zx']];
        }
        if (isset($param['phone_agent']) && !empty($param['phone_agent'])) {
            $whehe[] = ['a.phone_agent','=',$param['phone_agent']];
        }
        if (isset($param['me_is_circle']) && $param['me_is_circle'] != '') {
            $whehe[] = ['a.me_is_circle','=',$param['me_is_circle']];
        }
        if (isset($param['me_is_real']) && $param['me_is_real'] != '') {
            $whehe[] = ['a.me_is_real','=',$param['me_is_real']];
        }
        if (isset($param['me_is_enterprise']) && $param['me_is_enterprise'] != '') {
            $whehe[] = ['a.me_is_enterprise','=',$param['me_is_enterprise']];
        }
        if (isset($param['me_is_vip']) && $param['me_is_vip'] != '') {
            $whehe[] = ['a.me_is_vip','=',$param['me_is_vip']];
        }
        if (isset($param['me_is_auditing']) && $param['me_is_auditing'] != '') {
            $whehe[] = ['a.me_is_auditing','=',$param['me_is_auditing']];
        }
        if (isset($param['me_xn_zx']) && $param['me_xn_zx'] != '') {
            $whehe[] = ['a.me_xn_zx','=',$param['me_xn_zx']];
        }
        if (isset($param['is_shi']) && $param['is_shi'] != '') {
            $whehe[] = ['a.me_sex','=',2];
            $whehe[] = ['a.is_shi','=',$param['is_shi']];
        }
        if (isset($param['boy_fund']) && $param['boy_fund'] != '') {
            $whehe[] = ['a.me_sex','=',2];
            $whehe[] = ['a.boy_fund','=',$param['boy_fund']];
        }
        if (isset($param['is_gzh_register']) && $param['is_gzh_register'] != '') {
            $whehe[] = ['a.is_gzh_register','=',$param['is_gzh_register']];
        }

        $Common = New Common();//只能看见自己相关的用户
        $q_member_str = $Common->getMyXmemberIdStr($this->uid);
        $wheheShow = '';
        if(!empty($q_member_str)) {
            $wheheShow = "a.member_id in($q_member_str)";
        }

        $wheheVideo = '';
        if (isset($param['is_video']) && $param['is_video'] != '') {
            if($param['is_video'] == 0){
                $wheheVideo = "f.id is null";
            }else{
                $wheheVideo = "f.id is not null and f.status = 1";
            }
        }

        if (isset($param['is_chi']) && $param['is_chi'] != '') {
            $xxljrnsyxtsg = $Common->getConfigValue('xxljrnsyxtsg');//流量池女生
            $xxljrnsyxtsgArr = [0];
            if(!empty($xxljrnsyxtsg)){
                $xxljrnsyxtsgArr = explode('#', $xxljrnsyxtsg);
            }
            if($param['is_chi'] == 1){
                $whehe[] = ['a.member_id','in',$xxljrnsyxtsgArr];
            }else{
                $whehe[] = ['a.member_id','not in',$xxljrnsyxtsgArr];
            }
        }

        $zbgirllb = $Common->getConfigValue('zbgirllb');//坐班女
        $zbgirllbArr = [0];
        if(!empty($zbgirllb)){
            $zbgirllbArr = explode('#', $zbgirllb);
        }
        if (isset($param['is_tc']) && $param['is_tc'] != '') {
            if($param['is_tc'] == 1){
                $whehe[] = ['a.member_id','in',$zbgirllbArr];
            }else{
                $whehe[] = ['a.member_id','not in',$zbgirllbArr];
            }
        }

        $IndexTableModel = New IndexTableModel();
//        $data = Db::table('fa_member')
//            ->alias('a')
//            ->join("fa_member_fund b",'a.member_id = b.member_id','LEFT')
//            ->join("fa_car_authentication c",'a.member_id = c.member_id','LEFT')
//            ->join("fa_member d",'d.member_id = a.me_parent','LEFT')
//            ->join("fa_push_girl_num e",'a.member_id = e.member_id','LEFT')
//            ->join("fa_short_video f",'a.member_id = f.member_id','LEFT')
//            ->where($whehe)
//            ->where($whehetime)
//            ->where($wheheShow)
//            ->where($wheheVideo)
//            ->field('a.*,b.*,c.id as rz_id,c.add_admin_id,c.type as rz_type,d.member_id as fmember_id,d.me_uid as fme_uid,d.me_nick_name as fme_nick_name,e.chi_id')
//            ->order('a.member_id desc')
//            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $data = Db::table('fa_member')
            ->alias('a')
            ->join("fa_member_fund b", 'a.member_id = b.member_id', 'LEFT')
            ->join("fa_car_authentication c", 'a.member_id = c.member_id', 'LEFT')
            ->join("fa_member d", 'd.member_id = a.me_parent', 'LEFT')
            ->join("fa_push_girl_num e", 'a.member_id = e.member_id', 'LEFT')
            ->join("fa_short_video f", 'a.member_id = f.member_id', 'LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->where($wheheShow)
            ->where($wheheVideo)
//            ->where(function ($query) {
//                $query->whereNull('f.id')->whereOr('f.status', 1);
//            })
            ->field('a.*,b.*,c.id as rz_id,c.add_admin_id,c.type as rz_type,d.member_id as fmember_id,d.me_uid as fme_uid,d.me_nick_name as fme_nick_name,e.chi_id, COUNT(f.id) as video_count')
            ->group('a.member_id')
            ->order('a.member_id desc')
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);

        $qclist = $IndexTableModel->getList('fa_circle_list',"id != 0",'id,circle_name','id asc');
        $chiList = $IndexTableModel->getList('fa_push_girl_chi','status = 1','id,chi_name','id asc');
        $chiLists = [0=>0];
        if(!empty($chiList)){
            $chiLists = array_column($chiList, 'chi_name', 'id');
        }

        $adminid = $this->uid;
        $data->each(function ($v, $k)use($IndexTableModel,$qclist,$adminid,$chiLists,$zbgirllbArr) {
            $djMemberId = getDjParent($v['member_id']);
            $v['dj_member_id'] = $djMemberId['dj_member_id'];
            if(empty($djMemberId['bz_name'])){
                $v['dj_member_word'] = empty($djMemberId['dj_member_id'])?'自身':$djMemberId['dj_member_id'];
            }else{
                $v['dj_member_word'] = empty($djMemberId['dj_member_id'])?'自身':$djMemberId['dj_member_id'].'【'.$djMemberId['bz_name'].'】';
            }

            $v['tc_status'] = 0;//0无按钮 1打开同城女 2关闭同城女
            if($v['me_sex'] == 2){
                if(in_array($v['member_id'],$zbgirllbArr)){
                    $v['is_tc_word'] = '已设置';
                    $v['tc_status'] = 2;
                }else{
                    $v['is_tc_word'] = '未设置';
                    $v['tc_status'] = 1;
                }
            }
            $v['is_gzh_register_word'] = '否';
            if($v['is_gzh_register'] == 1){
                $v['is_gzh_register_word'] = '是';
            }

            $v['chi_status'] = 1;//0无按钮 1修改流量池
            $v['chi_word'] = '无';
            if(!empty($v['chi_id'])){
                $v['chi_word'] = isset($chiLists[$v['chi_id']])?$chiLists[$v['chi_id']]:'-';
            }
            if($v['me_sex'] != 2){
                $v['chi_word'] = '-';
                $v['chi_status'] = 0;
                $v['is_tc_word'] = '-';
                $v['tc_status'] = 0;
            }

            $v['rz_id'] = empty($v['rz_id'])?0:$v['rz_id'];//车辆认证表ID
            $v['add_admin_id'] = empty($v['add_admin_id'])?0:$v['add_admin_id'];//0为正常用户认证车辆    否则为后台管理端管理员添加，此字段填写管理员ID
            $v['rz_type'] = empty($v['rz_type'])?0:$v['rz_type'];//车辆认证类型 1个人车辆  2企业车辆

            //只有超管能看全部手机号
            if($adminid != 1){
                $v['me_phone'] = hide_phone_number($v['me_phone']);
            }

            $v['zr_img_word'] = '';
            $v['zr_dj_word'] = '无';
            if(!empty($v['zr_dj'])){
                switch($v['zr_dj']){
                    case '1': $v['zr_dj_word'] = '美丽';break;
                    case '2': $v['zr_dj_word'] = '中等';break;
                    case '3': $v['zr_dj_word'] = '一般';break;
                }
            }

            if(empty($v['me_parent'])){
                $v['me_parent_word'] = '无上级';$v['me_bind_type_word'] = '无上级';
            }else{
                //查询父级用户信息
                $finfoUid = !empty($v['fmember_id'])?'('.$v['fme_nick_name'].')':'-';
                $v['me_parent_word'] = $v['me_parent'].$finfoUid;

                $v['me_bind_type_word'] = '-';
                switch ($v['me_bind_admin']) {
                    case 1:$v['me_bind_type_word'] = '扫码绑定';break;
                    case 2:$v['me_bind_type_word'] = '注册绑定';break;
                    case 3:$v['me_bind_type_word'] = 'VIP绑定';break;
                    case 4:$v['me_bind_type_word'] = '漏绑绑定';break;
                    case 5:$v['me_bind_type_word'] = '后台绑定';break;
                }

            }
            switch($v['me_sex']){
                case '0': $v['me_sex_word'] = '未设置';break;
                case '1': $v['me_sex_word'] = '男';break;
                case '2': $v['me_sex_word'] = '女';break;
            }
//            switch($v['me_standing_type']){
//                case '0': $v['me_sex_word'] .=  '（无身份）';break;
//                case '1': $v['me_sex_word'] .=  '（个人）';break;
//                case '2': $v['me_sex_word'] .=  '（企业）';break;
//            }

            $v['me_status_time_word'] = '-';
            switch($v['me_status']){
                case '1': $v['me_status_word'] = '正常';$v['me_status_time_word'] = '未封禁';break;
                case '2': $v['me_status_word'] = '封禁';
                    if($v['me_status_time'] != -1 && $v['me_status_time'] != 0){
                        $v['me_status_time_word'] = date('Y-m-d H:i',$v['me_status_time']);
                    }else{
                        $v['me_status_time_word'] = '永久';
                    }
                    break;
            }

            $v['signout_time'] = '未注销';
            $v['isjc_phone'] = 1;//展示解除限制按钮
            if(!empty(strpos($v['me_phone'], 'zx'))){
                $zqPhone = explode('zx',$v['me_phone'])[0];
                $v['me_phone'] = $zqPhone.'（已注销）';
                $v['me_nick_name'] = explode('zx',$v['me_nick_name'])[0].'（已注销）';
                $v['me_status'] = 99;
                $v['me_status_time_word'] = '已注销';
                $signoutInfo = Db::table('fa_member_signout')->where("`member_id` = '{$v['member_id']}'")->field('id,add_time')->find();
                $v['signout_time'] = empty($signoutInfo)?'-':date('Y-m-d H:i:s',$signoutInfo['add_time']);
                if(abslength($zqPhone) != 11){
                    if(substr($zqPhone, -2) == 11){
                        $v['signout_time'] .= '(已解除限制)';
                        $v['isjc_phone'] = 2;
                    }
                }
            }else{
                $v['isjc_phone'] = 3;
            }

            switch($v['me_is_real']){
                case '0': $v['me_is_real_word'] = '未认证';$v['me_realidcard_word'] = '未认证';break;
                case '1':
                    if($v['me_status_time_word'] == '已注销'){
                        $v['me_is_real_word'] = '已注销';
                        $v['me_realidcard_word'] = '已注销';
                    }else{
                        $v['me_is_real_word'] = '已认证（'.$v['me_realname'].'）';
                        if($adminid != 1){
                            $v['me_realidcard_word'] = substr_replace($v['me_realidcard'], '****', 3, 13);
                        }else{
                            $v['me_realidcard_word'] = $v['me_realidcard'];
                        }
                    }
                    break;
            }

            switch($v['me_is_circle']){
                case '0': $v['me_is_circle_word'] = '未认证';break;
                case '1':
                    if($v['me_car_type'] == 1){
                        $v['me_is_circle_word'] = '私家车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 2){
                        $v['me_is_circle_word'] = '企业车辆（'.$v['me_carname'].'）';
                    }
                    if($v['me_car_type'] == 3){
                        $v['me_is_circle_word'] = '运营车辆（'.$v['me_carname'].'）';
                    }
                    break;
            }

            $v['me_circle_rz'] = '无';//消费/收益标准
            $v['me_circle_rz_tj'] = '';//认证途径

//            if(!empty($v['me_circle_str'])){
//                $circlearr = explode(',',$v['me_circle_str']);
//                $v['me_circle_str_word']  = '';
//                foreach ($circlearr as $kk=>$vv){
//                    foreach ($qclist as $kkk=>$vvv){
//                        if($vvv['id'] == $vv){
//                            $v['me_circle_str_word'] .= !empty($vvv['circle_name'])?$vvv['circle_name'].' / ':'-'.' / ';
//                            break;
//                        }
//                    }
//                }
//                foreach ($qclist as $kkk=>$vvv){
//                    if($vvv['id'] == $v['me_circle_id']){
//                        $v['me_circle_rz'] = $vvv['circle_name'];//消费/收益标准
//                        $carRzInfo = $IndexTableModel->getFind('fa_car_authentication',"`member_id` = '{$v['member_id']}'",'id,add_admin_id');
//                        if(empty($carRzInfo)){
//                            $v['me_circle_rz_tj'] = '（-）';
//                        }else{
//                            if($v['me_carname'] == '买圈车主' && empty($carRzInfo['add_admin_id'])){
//                                $v['me_circle_rz_tj'] = '（通过破圈）';
//                            }else{
//                                $v['me_circle_rz_tj'] = empty($carRzInfo['add_admin_id'])?'（通过行驶证）':'（管理端开通）';
//                            }
//                        }
//                        break;
//                    }
//                }
//                $v['me_circle_str_word'] = trim($v['me_circle_str_word'],' / ');//所在圈层 全部
//                $v['me_circle_str_word_sl'] = cutStr($v['me_circle_str_word'],8);//所在圈层 省略
//            }else{
//                $v['me_circle_str_word'] = '无';
//                $v['me_circle_str_word_sl'] = '无';
//            }
            $v['me_circle_str_word'] = '无';
            $v['me_circle_str_word_sl'] = '无';

            switch($v['me_is_enterprise']){
                case '0': $v['me_is_enterprise_word'] = '未认证';break;
                case '1': $v['me_is_enterprise_word'] = '已认证';break;
            }
            switch($v['me_is_vip']){
                case '0': $v['me_is_vip_word'] = '未开通';break;
                case '1': $v['me_is_vip_word'] = '已开通';break;
            }
            switch($v['me_is_auditing']){
                case '0': $v['me_is_auditing_word'] = '可审核';break;
                case '1': $v['me_is_auditing_word'] = '无资格';break;
            }
            switch($v['me_is_ofus']){
                case '0': $v['me_is_ofus_word'] = '否';break;
                case '1': $v['me_is_ofus_word'] = '是';break;
            }
            switch($v['me_is_gf']){
                case '0': $v['me_is_gf_word'] = '否';break;
                case '1': $v['me_is_gf_word'] = '是';break;
            }
            switch($v['me_is_sfsq']){
                case '0': $v['me_is_sfsq_word'] = '否';break;
                case '1': $v['me_is_sfsq_word'] = '是';break;
            }
            switch($v['me_is_nrsq']){
                case '0': $v['me_is_nrsq_word'] = '否';break;
                case '1': $v['me_is_nrsq_word'] = '是';break;
            }
            $v['me_add_time'] = date('m-d H:i',$v['me_add_time']);
            if(empty($v['me_area_code'])){
                $v['me_area_code_word'] = '未获取';
            }else{
//                $v['me_area_code_word'] = areaCodeToAddress($v['me_area_code']);
                $v['me_area_code_word'] = '//';
            }

//            $me_circle_str = $v['me_circle_str'];
//            $v['str'] = '';
//            if($me_circle_str){
//                $arr = explode(',',$me_circle_str);
//                foreach ($arr as $kk =>&$vv){
//                    $str = '花钱破圈,圈子Id：'.$vv;
//                    $find = Db::table("fa_car_authentication")->where("circle_id=$vv")->where("name!='直接破圈'")->find();
//                    if($find){
//                        $str = '车认证破圈,圈子Id：'.$vv;
//                    }
//                    $v['str'] .= $str.'<br>';
//                }
//                $v['str'] = trim($v['str'],'<br>');
//            }

            switch($v['me_zx']){
                case '0': $v['me_zx_word'] = '在线';break;
                case '1': $v['me_zx_word'] = '离线';break;
            }
            switch($v['me_xn_zx']){
                case '0': $v['me_xn_zx_word'] = '是';break;
                case '1': $v['me_xn_zx_word'] = '否';break;
            }
            switch($v['me_add_sort']){
                case '0': $v['me_add_sort_word'] = '否';break;
                case '1': $v['me_add_sort_word'] = '是';break;
            }
            switch($v['tc_sort']){
                case '0': $v['tc_sort_word'] = '否';break;
                case '1': $v['tc_sort_word'] = '是';break;
            }
            switch($v['is_shi']){
                case '0': $v['is_shi_word'] = '可以';break;
                case '1': $v['is_shi_word'] = '不可';break;
            }
            switch($v['boy_fund']){
                case '0': $v['boy_fund_word'] = '不可';break;
                case '1': $v['boy_fund_word'] = '可以';break;
            }
            $v['me_qd'] = !empty($v['me_qd'])?$v['me_qd']:'-';
            return $v;
        });

        //符合条件总用户数
        $memberNum = Db::table('fa_member')
            ->alias('a')
            ->where($whehe)
            ->where($whehetime)
            ->count('a.member_id');

        $boyzxNum = Db::table('fa_member')
            ->alias('a')
            ->where($whehe)
            ->where($whehetime)
            ->where("a.me_sex = 1 and a.me_zx = 0")
            ->count('a.member_id');
        $girlzxNum = Db::table('fa_member')
            ->alias('a')
            ->where($whehe)
            ->where($whehetime)
            ->where("a.me_sex = 2 and a.me_zx = 0")
            ->count('a.member_id');

        $showInfo = $Common->getMyAccountNumber($this->uid);

        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
            'memberNum' => $memberNum,
            'boyzxNum' => $boyzxNum,
            'girlzxNum' => $girlzxNum,
            'showinfo' => $showInfo,
        ]);
        return $this->fetch();
    }


    /**
     * 用户详情
     * User:@hang
     */
    public function getmemberinfo($id)
    {
        $JoinTableModel = New JoinTableModel();
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $JoinTableModel->getThreeJoinInfo("fa_member","fa_member_fund","fa_enterprise","a.member_id = b.member_id","a.member_id = c.member_id","a.member_id = '{$id}'",'a.*,b.wechat_openid,b.alipay_name,b.alipay_number,b.stamp_money,b.no_stamp_money,b.exposure_num,c.enterprise_name,c.enterprise_phone,c.enterprise_phone_two,c.enterprise_province,c.enterprise_city,c.enterprise_area,c.enterprise_address,c.enterprise_day,c.enterprise_time,c.enterprise_img,c.enterprise_letter,c.enterprise_status','a.member_id asc');
        switch ($memberInfo['me_zx']){
            case 1;$memberInfo['me_zx'] = '离线';break;
            case 0;$memberInfo['me_zx'] = '在线';break;
        }
        $memberInfo['me_add_time'] = date('Y-m-d H:i:s',$memberInfo['me_add_time']);
        if(empty($memberInfo['me_parent'])){
            $memberInfo['me_parent'] = '未绑定';
            $memberInfo['me_bind_type'] = '未绑定';
        }else{
            $finfo = $IndexTableModel->getFind('fa_member',"member_id = '{$memberInfo['me_parent']}'",'member_id,me_uid,me_phone,me_nick_name');
            $memberInfo['me_parent'] = '【融云ID：'.$memberInfo['me_parent'].'】'.'【UID：'.$finfo['me_uid'].'】'.'【手机号：'.$finfo['me_phone'].'】'.'【昵称：'.$finfo['me_nick_name'].'】';
            if($memberInfo['me_bind_type'] == 1){
                $memberInfo['me_bind_type'] = '扫码绑定';
            }else{
                $memberInfo['me_bind_type'] = 'VIP绑定';
            }
        }
        switch($memberInfo['me_sex']){
            case '0': $memberInfo['me_sex'] = '未设置';break;
            case '1': $memberInfo['me_sex'] = '男';break;
            case '2': $memberInfo['me_sex'] = '女';break;
        }
        $memberInfo['me_age'] = empty($memberInfo['me_age'])?'未填写':$memberInfo['me_age'];
        $memberInfo['me_status_time_word'] = '-';
        switch($memberInfo['me_status']){
            case '1': $memberInfo['me_status'] = '正常';$memberInfo['me_status_time_word'] = '未封禁';break;
            case '2': $memberInfo['me_status'] = '已封禁';
                if($memberInfo['me_status_time'] != -1 && $memberInfo['me_status_time'] != 0){
                    $memberInfo['me_status_time_word'] = date('Y-m-d H:i:s',$memberInfo['me_status_time']);
                }else{
                    $memberInfo['me_status_time_word'] = '永久';
                }
            break;
        }
        if(!empty(strpos($memberInfo['me_phone'], 'zx'))){
            $memberInfo['me_phone'] = explode('zx',$memberInfo['me_phone'])[0].'（已注销）';
            $memberInfo['me_nick_name'] = explode('zx',$memberInfo['me_nick_name'])[0].'（已注销）';
            $memberInfo['me_status_time_word'] = '已注销';
            $memberInfo['me_status'] = '已注销';
        }
        switch($memberInfo['me_is_real']){
            case '0': $memberInfo['me_is_real'] = '未认证';break;
            case '1': $memberInfo['me_is_real'] = '已认证';break;
        }
        switch($memberInfo['me_is_circle']){
            case '0': $memberInfo['me_is_circle'] = '未认证';break;
            case '1': $memberInfo['me_is_circle'] = '已认证';break;
        }
        $qclist = $IndexTableModel->getList('fa_circle_list',"id != 0",'id,circle_name','id asc');
        if(!empty($memberInfo['me_circle_id'])){
            foreach ($qclist as $k=>$v){
                if($v['id'] == $memberInfo['me_circle_id']){
                    $memberInfo['me_circle_id'] = !empty($v['circle_name'])?$v['circle_name']:'-';
                    $carRzInfo = $IndexTableModel->getFind('fa_car_authentication',"`member_id` = '{$memberInfo['member_id']}'",'id,add_admin_id');
                    if(empty($carRzInfo)){
                        $memberInfo['me_circle_id'] .= '（-）';
                    }else{
                        if($memberInfo['me_carname'] == '买圈车主' && empty($carRzInfo['add_admin_id'])){
                            $memberInfo['me_circle_id'] .= '（通过破圈）';
                        }else{
                            $memberInfo['me_circle_id'] .= empty($carRzInfo['add_admin_id'])?'（通过行驶证）':'（管理端开通）';
                        }
                    }
                    break;
                }
            }
        }else{
            $memberInfo['me_circle_id'] = '未认证';
        }
        if(!empty($memberInfo['me_circle_str'])){
            $circlearr = explode(',',$memberInfo['me_circle_str']);
            $memberInfo['me_circle_str_word']  = '';
            foreach ($circlearr as $k=>$v){
                foreach ($qclist as $kk=>$vv){
                    if($vv['id'] == $v){
                        $memberInfo['me_circle_str_word'] .= !empty($vv['circle_name'])?$vv['circle_name'].' / ':'-'.' / ';
                        break;
                    }
                }
            }
            $memberInfo['me_circle_str_word'] = trim($memberInfo['me_circle_str_word'],' / ');
        }else{
            $memberInfo['me_circle_str'] = '无';
        }
        if($memberInfo['me_is_enterprise'] == 1){
            $memberInfo['enterprise_name_wrod'] = $memberInfo['enterprise_name'];
            $memberInfo['enterprise_phone_wrod'] = $memberInfo['enterprise_phone'].' / '.$memberInfo['enterprise_phone_two'];
            $memberInfo['enterprise_address_word'] = $memberInfo['enterprise_province'].$memberInfo['enterprise_city'].$memberInfo['enterprise_area'].$memberInfo['enterprise_address'];
            $memberInfo['enterprise_day_word'] = $memberInfo['enterprise_day'].$memberInfo['enterprise_time'];
            $memberInfo['enterprise_img_word'] = $memberInfo['enterprise_img'];
            $memberInfo['enterprise_letter_word'] = $memberInfo['enterprise_letter'];
        }else{
            $memberInfo['enterprise_name_wrod'] = '未认证';$memberInfo['enterprise_phone_wrod'] = '未认证';$memberInfo['enterprise_address_word'] = '未认证';$memberInfo['enterprise_day_word'] = '未认证';$memberInfo['enterprise_img_word'] = '';$memberInfo['enterprise_letter_word'] = '';
        }
        switch($memberInfo['me_is_enterprise']){
            case '0': $memberInfo['me_is_enterprise'] = '未认证';break;
            case '1': $memberInfo['me_is_enterprise'] = '已认证';break;
        }
        if($memberInfo['me_is_vip'] == 0){
            $memberInfo['me_is_vip'] = '未开通';
            $memberInfo['me_vip_overtime'] = '未开通';
        }else{
            $memberInfo['me_is_vip'] = '已开通';
            $memberInfo['me_vip_overtime'] = date('Y-m-d H:i:s',$memberInfo['me_vip_overtime']);
        }
        if(!empty($memberInfo['wechat_openid'])){
            $memberInfo['wechat_openid'] = '已绑定';
        }else{
            $memberInfo['wechat_openid'] = '未绑定';
        }
        $adminid = $this->uid;
        //只有超管能看全部手机号
        if($adminid != 1){
            $memberInfo['me_phone'] = hide_phone_number($memberInfo['me_phone']);
        }

        $this->assign([
            'data' => $memberInfo,
            'member_id' => $id,
        ]);
        return $this->fetch();
    }


    /**
     * 封禁用户页面
     * User:@hang
     */
    public function disableview($id){
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'",'member_id,me_uid,me_nick_name');
        $list = ['-1'=>'永久封禁','1'=>'1小时','3'=>'3小时','12'=>'12小时','24'=>'1天','72'=>'3天','168'=>'7天','720'=>'30天','8760'=>'1年'];
        $lylist = ['引流','涉黄','招呼语违规','言语存在诱导，并且视频无交付','存在无脸视频，搪塞敷衍行为'];
        $this->assign([
            'memberinfo' => $memberInfo,
            'member_id' => $id,
            'list' => $list,
            'lylist' => $lylist,
        ]);
        return $this->fetch();
    }

    /**
     * 封禁用户
     * User:@hang
     */
    public function disable(){
        $id = input('member_id');
        $time = input('time');//封禁小时数
        $me_status_ly = input('me_status_ly');//封禁理由
        $content = input('content');//封禁原因
        if(empty($content)){
            return admin_error('请填写封禁原因，可用于后期追溯',URL_CLOSE_REFRESH);
        }
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:disablemember'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        if(empty($time) || $time == -1){
            //永久封禁
            $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_status'=>2,'me_status_time'=>-1,'me_status_ly'=>$me_status_ly));
            $word = '【永久封禁】理由：'.$me_status_ly.'；原因：'.$content;
        }else{
            //时长封禁
            $end_time = bcadd(time(),bcmul($time,3600,0),0);
            $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_status'=>2,'me_status_time'=>$end_time,'me_status_ly'=>$me_status_ly));
            $word = '【自动解封时间：'.date('Y-m-d H:i:s',$end_time).'】理由：'.$me_status_ly.'；原因：'.$content;
        }
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('封禁用户失败',URL_CLOSE_REFRESH);
        }
        //修改用户头像和昵称
        $fj_me_img = 'http://uploads-ydxc.oss-accelerate.aliyuncs.com/rearend/6efb9ba471c16a0c5645ef67752f3f9732a78918.png';
        $fj_me_nick_name = '风险违规封号';
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'","member_id,me_uid,me_img,me_phone,me_nick_name");
        $IndexTableModel->addInfo('fa_member_fjinfo',['member_id'=>$id,'me_img'=>$memberInfo['me_img'],'me_nick_name'=>$memberInfo['me_nick_name']]);
        $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_img'=>$fj_me_img,'me_nick_name'=>$fj_me_nick_name));
        $RyImLogic = new RyImLogic();
        $RyImLogic->editryAccountImportMmeberInfo($id,$fj_me_nick_name,$fj_me_img);

        $data = array();
        $data['user_id'] = $this->uid;
        $data['type'] = 1;
        $data['member_id'] = $id;
        $data['content'] = '【'.$memberInfo['member_id'].'】被后台管理员封禁->'.$word;
        $data['add_time'] = time();
        $IndexTableModel->addInfo('fa_user_operate_log',$data);

        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('封禁用户成功', URL_RELOAD);
    }


    /**
     * 解除封禁用户
     * User:@hang
     */
    public function enable($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:enablemember'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_status'=>1,'me_status_time'=>0,'me_status_ly'=>''));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('解封用户失败',URL_CLOSE_REFRESH);
        }
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'","member_id,me_uid,me_phone,me_nick_name");

        //恢复用户头像和昵称
        $zInfo = $IndexTableModel->getFindOrder('fa_member_fjinfo',['member_id'=>$id],'*','id desc');
        if(!empty($zInfo)){
            $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_img'=>$zInfo['me_img'],'me_nick_name'=>$zInfo['me_nick_name']));
            $RyImLogic = new RyImLogic();
            $RyImLogic->editryAccountImportMmeberInfo($id,$zInfo['me_nick_name'],$zInfo['me_img']);
        }

        $data = array();
        $data['user_id'] = $this->uid;
        $data['type'] = 2;
        $data['member_id'] = $id;
        $data['content'] = '【'.$memberInfo['member_id'].'】被后台管理员解封';
        $data['add_time'] = time();
        $IndexTableModel->addInfo('fa_user_operate_log',$data);

        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('解封用户成功', URL_RELOAD);
    }




    /**
     * 取消用户短视频审核资格
     * User:@hang
     */
    public function auditingdisable($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:auditingdisable'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_is_auditing'=>1));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }


    /**
     * 恢复用户短视频审核资格
     * User:@hang
     */
    public function auditingenable($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:auditingenable'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_is_auditing'=>0));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    /**
     * 为用户通过车辆认证 页面
     * User:@hang
     */
    public function passcarauthentication($id)
    {
        //查询用户信息
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'",'member_id,me_uid,me_phone,me_nick_name');
        //圈层列表
        $circle_list = $IndexTableModel->getList('fa_circle_list',"`circle_status` = 1",'id,circle_name','id asc');
        $this->assign([
            'data' => $id,
            'memberinfo' => $memberInfo,
            'circle_list' => $circle_list
        ]);
        return $this->fetch();
    }


    /**
     * 确认 为用户通过车辆认证
     * User:@hang
     */
    public function actionpasscarauthentication()
    {
        $member_id = input('member_id');
        $type = input('type');
        $name = input('name');
        if(empty($name)){
            return admin_error('请输入姓名或企业名',URL_CLOSE_REFRESH);
        }
        $car_name = input('car_name');
        if(empty($car_name)){
            return admin_error('请输入车辆名称',URL_CLOSE_REFRESH);
        }
//        if($car_name == '买圈车主'){
//            return admin_error('抱歉，用户手机端花钱破圈是这个名称，冲突了',URL_CLOSE_REFRESH);
//        }
        $circle_id = input('circle_id');
        if(empty($circle_id)){
            return admin_error('请选择进入的圈层',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        $circleInfo = $IndexTableModel->getFind('fa_circle_list',"`id` = '{$circle_id}' and `circle_status` = 1",'*');
        if(empty($circleInfo)){
            return admin_error('圈层已经被禁用',URL_CLOSE_REFRESH);
        }
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:actionpasscarauthentication'.$member_id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试',URL_CLOSE_REFRESH);
        }
        $ctime = time();
        Db::startTrans();
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$member_id}'",'*');
        if(empty($memberInfo)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户信息查询失败',URL_CLOSE_REFRESH);
        }
        if($memberInfo['me_is_circle'] != 0 || $memberInfo['me_circle_id'] != 0){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户已经完成了车辆认证，请检查',URL_CLOSE_REFRESH);
        }
        $carAuthenticationInfo = $IndexTableModel->getFind('fa_car_authentication',"`member_id` = '{$member_id}'",'*');
        $data = array();
        $data['add_admin_id'] = $this->uid;
        $data['member_id'] = $member_id;
        $data['type'] = $type;
        $data['img'] = 'https://carmanage.yiyankeji.vip/uploads/moren/xingshizheng.png';
        $data['state_video'] = $type == 1?'':'https://carmanage.yiyankeji.vip/uploads/moren/shouchixingshizheng.mp4';
        $data['name'] = $name;
        $data['car_vin'] = 'VIN'.$member_id.rand(0,9).rand(0,9);
        $data['car_name'] = $car_name;
        $data['car_all_name'] = $car_name;
        $data['car_model'] = 'CP'.$member_id.rand(0,9).rand(0,9);
        $data['car_price'] = $circleInfo['circle_line'];
        $data['car_money'] = delete0(bcdiv($circleInfo['circle_line'],10000,5));
        $data['vin_info_json'] = '{"result":1}';
        $data['car_info_json'] = '{"member_id":'.$member_id.'}';
        $data['status'] = 2;
        $data['add_time'] = $ctime;
        $data['circle_id'] = $circle_id;
        $data['state'] = 1;
        $data['is_pass'] = 1;
        if(empty($carAuthenticationInfo)){
            //未进行过认证
            $res = $IndexTableModel->addInfo('fa_car_authentication',$data);
            if(empty($res)){
                Db::rollBack();
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('车辆认证信息添加失败',URL_CLOSE_REFRESH);
            }
        }else{
            //进行过认证
            $data['sh_admin_id'] = 0;$data['sh_content'] = '';$data['sh_time'] = 0;
            $updateRes = $IndexTableModel->editInfo('fa_car_authentication',"`id` = '{$carAuthenticationInfo['id']}'",$data);
            if(empty($updateRes)){
                Db::rollBack();
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('用户之前车辆认证过，车辆认证信息修改失败',URL_CLOSE_REFRESH);
            }
            $res = $carAuthenticationInfo['id'];
        }

        $me_circle_str = $circle_id;
        $recharge_circle_order_list = $IndexTableModel->getList('fa_recharge_circle_order',"`member_id` = '{$member_id}'",'id,member_id,circle_id','id asc');
        if(!empty($recharge_circle_order_list)){
            foreach ($recharge_circle_order_list as $k=>$v){
                $me_circle_str .= ','.$v['circle_id'];
            }
        }
        $memberRes = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$member_id}'",array('me_is_circle'=>1,'me_car_type'=>$type,'me_carname'=>$car_name,'me_circle_id'=>$circle_id,'me_circle_url'=>$circleInfo['circle_url'],'me_circle_str'=>trim($me_circle_str,',')));
        if(empty($memberRes)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户车辆认证信息修改失败',URL_CLOSE_REFRESH);
        }
        //增加服务通知
        $typeName = $type == 1?'私家':'企业';
        $newRes = $IndexTableModel->addInfo('fa_news_service',array('type'=>9,'member_id'=>$member_id,'j_member_id'=>$member_id,'g_table'=>'fa_car_authentication','g_id'=>$res,'content'=>'您于 '.date('Y年m月d日 H:i:s',$ctime).' 成功认证'.$typeName.'车辆，认证通过圈层为【'.$circleInfo['circle_name'].'】，认证车辆为【'.$car_name.'】。','is_read'=>0,'add_time'=>$ctime));
        if(empty($newRes)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('增加服务通知失败',URL_CLOSE_REFRESH);
        }

        Db::commit();
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('为用户直接【通过车辆认证】成功',URL_CLOSE_REFRESH);
    }


    //特殊用户
    public function editofus($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:editofus'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_is_ofus'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //官方用户
    public function editgf($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:editgf'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_is_gf'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //三方授权用户
    public function editsfsq($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:editsfsq'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_is_sfsq'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //官方内容授权用户
    public function editnrsq($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:editnrsq'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_is_nrsq'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //使用权限 打开/关闭
    public function editisshi($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:editisshi'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('is_shi'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //查看余额 打开/关闭
    public function editboyfund($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:editboyfund'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('boy_fund'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //虚拟在线打开/关闭
    public function editxnzx($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:editxnzx'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_xn_zx'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //新注册靠前
    public function editxzckq($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:editxzckq'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_add_sort'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //同城页靠前
    public function edittckq($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:edittckq'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $index = input('index');
        $IndexTableModel = New IndexTableModel();
        $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('tc_sort'=>$index));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }


    /**
     * 清除车辆认证
     * User:@hang
     */
    public function delmemberprivate($id)
    {
        $IndexTableModel = New IndexTableModel();
        $carAuthenticationInfo = $IndexTableModel->getFind('fa_car_authentication',"`id` = '{$id}'",'id,member_id');
        if(empty($carAuthenticationInfo)){
            return admin_error('抱歉，车辆认证信息查询错误',URL_CLOSE_REFRESH);
        }
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:delprivate'.$carAuthenticationInfo['member_id'];	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试',URL_CLOSE_REFRESH);
        }
        $FacarauthenticationController = New FacarauthenticationController();
        $res = $FacarauthenticationController->delmembercircle($carAuthenticationInfo['member_id']);
        if($res != 200){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error($res,URL_CLOSE_REFRESH);
        }
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('清除用户车辆认证信息成功',URL_CLOSE_REFRESH);
    }

























    /**
     * 修改用户资料页面(暂时无用)
     * User:@hang
     */
    public function editmemberinfo($id){
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'",'*');
        //可选择的行业
        $industry_list = $IndexTableModel->getList('fa_member_industry',"`status` = 1","CAST(id AS char) as me_industry_id,name as industry_name","id asc");
        //年收入
        $nsy_list = ['5W以下'=>'5W以下','5W-10W'=>'5W-10W','10W-20W'=>'10W-20W','20W-50W'=>'20W-50W','50W-100W'=>'50W-100W','100W-300W'=>'100W-300W','300W-500W'=>'300W-500W','500W以上'=>'500W以上'];
        //情感状态
        $qgzt_list = ['1'=>'热恋','2'=>'分手','3'=>'已婚','4'=>'未婚','5'=>'离异'];
        //年龄
        //身高
        //体重
        $this->assign([
            'memberinfo' => $memberInfo,
            'member_id' => $id,
            'industry_list' => $industry_list,
            'nsy_list' => $nsy_list,
            'qgzt_list' => $qgzt_list,
        ]);
        return $this->fetch();
    }


    /**
     * 确认用户资料页面(暂时无用)
     * User:@hang
     */
    public function actioneditmemberinfo(){
        die;
        $id = input('member_id');
        $time = input('time');//封禁小时数

        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:disablemember'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        if(empty($time) || $time == -1){
            //永久封禁
            $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_status'=>2,'me_status_time'=>-1));
            $word = '【永久封禁】';
        }else{
            //时长封禁
            $end_time = bcadd(time(),bcmul($time,3600,0),0);
            $res = $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_status'=>2,'me_status_time'=>$end_time));
            $word = '【'.date('Y-m-d H:i:s',$end_time).'】';
        }
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('封禁用户失败',URL_CLOSE_REFRESH);
        }
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'","member_id,me_uid,me_phone,me_nick_name");
        $data = array();
        $data['user_id'] = $this->uid;
        $data['type'] = 1;
        $data['member_id'] = $id;
        $data['content'] = '【'.$memberInfo['me_uid'].'】被后台管理员封禁，自动解封时间：'.$word;
        $data['add_time'] = time();
        $IndexTableModel->addInfo('fa_user_operate_log',$data);

        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('封禁用户成功', URL_RELOAD);
    }


    /**
     * 私人定制列表
     * User:@hang
     */
    public function personalized(Request $request)
    {
        $param = $request->param();
        $whehe = array();
        if (isset($param['member_id']) && !empty($param['member_id'])) {
            $whehe[] = ['b.member_id','=',$param['member_id']];
        }
        if (isset($param['me_uid']) && !empty($param['me_uid'])) {
            $whehe[] = ['b.me_uid','like',"%{$param['me_uid']}%"];
        }
        if (isset($param['me_phone']) && !empty($param['me_phone'])) {
            $whehe[] = ['b.me_phone','like',"%{$param['me_phone']}%"];
        }
        $whehetime = '';
        if (isset($param['me_add_time']) && !empty($param['me_add_time'])) {
            $time_arr = explode(' - ', $param['me_add_time']);
            $start_time = strtotime($time_arr[0]);
            $end_time = strtotime($time_arr[1]);
            $whehetime = "b.me_add_time >= $start_time AND b.me_add_time <= $end_time";
        }

        $IndexTableModel = New IndexTableModel();
        $data = Db::table('fa_member_siren')
            ->alias('a')
            ->join("fa_member b",'a.member_id = b.member_id','LEFT')
            ->where($whehe)
            ->where($whehetime)
            ->field('a.*,b.me_uid,b.me_phone,b.me_nick_name,b.me_add_time')
            ->order('a.member_id desc')
            ->paginate($this->admin['per_page'],false,['query'=>request()->param()]);
        $adminid = $this->uid;
        $data->each(function ($v, $k)use($IndexTableModel,$adminid) {
            //只有超管能看全部手机号
            if($adminid != 1){
                $v['me_phone'] = hide_phone_number($v['me_phone']);
            }
            if(!empty(strpos($v['me_phone'], 'zx'))){
                $v['me_phone'] = explode('zx',$v['me_phone'])[0].'（已注销）';
                $v['me_nick_name'] = explode('zx',$v['me_nick_name'])[0].'（已注销）';
            }
            $v['me_add_time'] = date('Y-m-d H:i',$v['me_add_time']);
            $v['add_time'] = date('Y-m-d H:i',$v['add_time']);
            $v['imgs_arr'] = !empty($v['imgs'])?explode(',',$v['imgs']):[];
            return $v;
        });

        //关键词，排序等赋值
        $this->assign($request->get());
        $this->assign([
            'data'  => $data,
            'page'  => $data->render(),
            'total' => $data->total(),
        ]);
        return $this->fetch();
    }



    /**
     * 真人信息
     * User:@hang
     */
    public function getzrinfo($id){
        $IndexTableModel = New IndexTableModel();
        if (!empty(input('is_add'))) {
            $member_id = input('member_id');
            //操作上锁
            $Redis_Lock  =  new \Redislock();
            $otc_sell_key  =  'lock:getzrinfoedit'.$member_id;	// 定义锁标识
            $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
            //解锁失败
            if(!$is_lock){
                return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
            }
            $data = array();
            $data['zr_dj'] = input('zr_dj');
            //真人照片
            if (!empty($_FILES['zr_img']['name'])) {
                $Aliuploadimage = New Aliuploadimage();
                $file = request()->file('zr_img');//获取图片流文件
                $applogourlRes = $Aliuploadimage->setImages($file);
                if($applogourlRes['code'] != 200){
                    return admin_error('真人图片上传失败:'.$applogourlRes['msg'], URL_RELOAD);
                }else{
                    $data['zr_img'] = $applogourlRes['data']['url'];
                }
            }
            $IndexTableModel->editInfo('fa_member',"`member_id` = '{$member_id}'",$data);
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_success('更新真人信息成功', URL_CLOSE_REFRESH);
        }
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'",'member_id,me_nick_name,zr_img,zr_dj');
        $list = ['1'=>'美丽','2'=>'中等','3'=>'一般'];
        $this->assign([
            'memberinfo' => $memberInfo,
            'member_id' => $id,
            'list' => $list,
        ]);
        return $this->fetch();
    }


    /**
     * 修改用户性别
     * User:@hang
     */
    public function setmembersex($id){
        $IndexTableModel = New IndexTableModel();
        if (!empty(input('is_add'))) {
            $member_id = input('member_id');
            //操作上锁
            $Redis_Lock  =  new \Redislock();
            $otc_sell_key  =  'lock:setmembersex'.$member_id;	// 定义锁标识
            $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
            //解锁失败
            if(!$is_lock){
                return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
            }
            $new_sex = input('new_sex');
            $IndexTableModel->editInfo('fa_member',"`member_id` = '{$member_id}'",['me_sex'=>$new_sex]);
            $IndexTableModel->editInfo('fa_member_fund',"`member_id` = '{$member_id}'",['sex'=>$new_sex]);

            $new_sex_word = $new_sex == 1?'男':'女';
            $data = array();
            $data['user_id'] = $this->uid;
            $data['type'] = 15;
            $data['member_id'] = $member_id;
            $data['d_member_id'] = 0;
            $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$member_id}'",'member_id,me_uid,me_bind_type,me_parent');
            $data['content'] = '为【'.$memberInfo['member_id'].'】修改性别为【'.$new_sex_word.'】';
            $data['add_time'] = time();
            $logRes = $IndexTableModel->addInfo('fa_user_operate_log',$data);

            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_success('修改性别成功', URL_CLOSE_REFRESH);
        }
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'",'member_id,me_nick_name,me_sex');
        if($memberInfo['me_sex'] == 0) $memberInfo['me_sex_word'] = '未设置';
        if($memberInfo['me_sex'] == 1) $memberInfo['me_sex_word'] = '男';
        if($memberInfo['me_sex'] == 2) $memberInfo['me_sex_word'] = '女';
        $list = ['1'=>'男','2'=>'女'];
        $this->assign([
            'memberinfo' => $memberInfo,
            'member_id' => $id,
            'list' => $list,
        ]);
        return $this->fetch();
    }


    /**
     * 取消用户实名
     * User:@hang
     */
    public function setmemberrealdel($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:setmemberrealdel'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        $res =  $IndexTableModel->editInfo('fa_member',array('member_id'=>$id),array('me_is_real'=>0,'me_realname'=>'','me_realidcard'=>'','me_yzh'=>0));
        if(empty($res)){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('操作失败',URL_CLOSE_REFRESH);
        }
        $IndexTableModel->delOne('fa_member_trueimg',array('member_id'=>$id));
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }


    /**
     * 设置流量池推送 / 关闭流量池推送  页面
     * User:@hang
     */
    public function setchiview($id){
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'",'member_id,me_uid,me_nick_name');
        $chiList = $IndexTableModel->getList('fa_push_girl_chi','status = 1','*','id asc');
        $this->assign([
            'memberinfo' => $memberInfo,
            'member_id' => $id,
            'list' => $chiList,
        ]);
        return $this->fetch();
    }

    /**
     * 确认 设置流量池推送 / 关闭流量池推送
     * User:@hang
     */
    public function actionsetchi(){
        $member_id = input('member_id');
        $chi_id = input('chi_id');//-99为关闭 否则为流量池ID

        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:actionsetchi'.$member_id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        $Common = New Common();
        $xxljrnsyxtsg = $Common->getConfigValue('xxljrnsyxtsg');//流量池女生
        $xxljrnsyxtsgArr = [];
        if(!empty($xxljrnsyxtsg)){
            $xxljrnsyxtsgArr = explode('#', $xxljrnsyxtsg);
        }
//        $uniqueArray = array_unique($xxljrnsyxtsgArr); // 去重
//        $realCount = count($uniqueArray);    // 获取数量
//        var_dump($realCount);die;//参与评级的流量池女总人数
        $ctime = time();
        $newxxljrnsyxtsg = '';
        if($chi_id == -99){
            //关闭此用户流量池功能
//            $key = array_search($member_id,$xxljrnsyxtsgArr);
//            if($key !== false){
//                unset($xxljrnsyxtsgArr[$key]);
//                $newxxljrnsyxtsg = trim(implode('#',$xxljrnsyxtsgArr),'#');
//            }else{
//                $newxxljrnsyxtsg = $xxljrnsyxtsg;
//            }
            if(!empty($xxljrnsyxtsgArr)){
                foreach ($xxljrnsyxtsgArr as $k=>$v){
                    if($v == $member_id){
                        unset($xxljrnsyxtsgArr[$k]);
                        break;
                    }
                }
                $newxxljrnsyxtsg = trim(implode('#',$xxljrnsyxtsgArr),'#');
            }
            $pushInfo = $IndexTableModel->getFind('fa_push_girl_num',"`member_id` = '{$member_id}'",'*');
            if(!empty($pushInfo)){
                $IndexTableModel->editInfo('fa_push_girl_num',"`id` = '{$pushInfo['id']}'",array('day_num'=>0,'chi_id'=>0,'add_time'=>$ctime));
            }else{
                $IndexTableModel->addInfo('fa_push_girl_num',array('member_id'=>$member_id,'num'=>0,'day_num'=>0,'chi_id'=>0,'add_time'=>$ctime));
            }
            $IndexTableModel->editInfo('fa_config',"`config_key` = 'xxljrnsyxtsg'",['config_value'=>$newxxljrnsyxtsg]);
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_success('关闭用户【流量池推送】成功', URL_RELOAD);
        }else{
            //修改此用户流量池功能
            $chiInfo = $IndexTableModel->getFind('fa_push_girl_chi',"status = 1 and id = '{$chi_id}'",'*');
            if(empty($chiInfo)){
                $Redis_Lock->unlock($otc_sell_key);	//释放锁
                return admin_error('流量池信息未查询到',URL_CLOSE_REFRESH);
            }
            //查询是否已经在流量池内
            if(!empty($xxljrnsyxtsgArr)){
                $index = 2;//1在 2不在
                foreach ($xxljrnsyxtsgArr as $k=>$v){
                    if($v == $member_id){
                        $index = 1;
                        break;
                    }
                }
                if($index == 2){
                    $newxxljrnsyxtsg = trim($xxljrnsyxtsg.'#'.$member_id,'#');
                }else{
                    $newxxljrnsyxtsg = $xxljrnsyxtsg;
                }
            }else{
                $newxxljrnsyxtsg = $member_id;
            }
//            $Redis_Lock->unlock($otc_sell_key);	//释放锁
//            var_dump($newxxljrnsyxtsg);die;
            $pushInfo = $IndexTableModel->getFind('fa_push_girl_num',"`member_id` = '{$member_id}'",'*');
            if(!empty($pushInfo)){
                $IndexTableModel->editInfo('fa_push_girl_num',"`id` = '{$pushInfo['id']}'",array('day_num'=>$chiInfo['push_num'],'chi_id'=>$chiInfo['id'],'add_time'=>$ctime));
            }else{
                $IndexTableModel->addInfo('fa_push_girl_num',array('member_id'=>$member_id,'num'=>0,'day_num'=>$chiInfo['push_num'],'chi_id'=>$chiInfo['id'],'add_time'=>$ctime));
            }
            $IndexTableModel->editInfo('fa_config',"`config_key` = 'xxljrnsyxtsg'",['config_value'=>$newxxljrnsyxtsg]);
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_success('开启用户【流量池推送】成功', URL_RELOAD);
        }
    }


    /**
     * 打开/关闭 同城女
     * User:@hang
     */
    public function edittczbv($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:edittczbv'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $Common = New Common();
        $zbgirllb = $Common->getConfigValue('zbgirllb');//坐班女
        $zbgirllbArr = [0];
        if(!empty($zbgirllb)){
            $zbgirllbArr = explode('#', $zbgirllb);
        }
        $newzbgirllb = '';
        $index = input('index');
        if($index == 0){
            //打开
            if(in_array($id,$zbgirllbArr)){
                $newzbgirllb = $zbgirllb;
            }else{
                $newzbgirllb = trim($zbgirllb.'#'.$id,'#');
            }
        }else{
            //关闭
            if(!empty($zbgirllbArr)){
                foreach ($zbgirllbArr as $k=>$v){
                    if($v == $id){
                        unset($zbgirllbArr[$k]);
                        break;
                    }
                }
                $newzbgirllb = trim(implode('#',$zbgirllbArr),'#');
            }
        }
        $IndexTableModel = New IndexTableModel();
        $IndexTableModel->editInfo('fa_config',"`config_key` = 'zbgirllb'",['config_value'=>$newzbgirllb]);

        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }



    /**
     * 为此用户设置备注姓名 页面
     * User:@hang
     */
    public function setbzname($id)
    {
        //查询提现详情
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'",'member_id,me_uid,me_phone,me_nick_name,me_sex,me_realname,me_realidcard,bz_name');
        $this->assign([
            'data' => $id,
            'memberinfo' => $memberInfo,
        ]);
        return $this->fetch();
    }


    /**
     * 确认 修改用户备注姓名
     * User:@hang
     */
    public function actionsetbzname()
    {
        $id = input('id');
        $bz_name = input('bz_name');
        $IndexTableModel = New IndexTableModel();
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:actionsetbzname'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试',URL_CLOSE_REFRESH);
        }
        $IndexTableModel->editInfo('fa_member',"`member_id` = {$id}",['bz_name'=>$bz_name]);
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('设置成功',URL_CLOSE_REFRESH);
    }


    //解除此用户【手机号】和【设备】封禁
    public function jcmemberfj($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:jcmemberfj'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',"`member_id` = '{$id}'",'*');
        if($memberInfo['me_zhuxiao'] != 1){
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户并未注销',URL_CLOSE_REFRESH);
        }
        $zqPhone = explode('zx',$memberInfo['me_phone'])[0];
        $zqPhonehz = explode('zx',$memberInfo['me_phone'])[1];
        if(!empty(strpos($memberInfo['me_phone'], 'zx'))){
            if(abslength($zqPhone) != 11){
                if(substr($zqPhone, -2) == 11){
                    $Redis_Lock->unlock($otc_sell_key);	//释放锁
                    return admin_error('此手机号已经解除过限制',URL_CLOSE_REFRESH);
                }
            }
        }else{
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户并未注销',URL_CLOSE_REFRESH);
        }
        $newPhone = $zqPhone.'11zx'.$zqPhonehz;
        $IndexTableModel->editInfo('fa_member',"`member_id` = '{$id}'",array('me_phone'=>$newPhone));
        $zxInfo = $IndexTableModel->getFind('fa_member_signout',"`member_id` = '{$id}'",'*');
        if(!empty($zxInfo)){
            $IndexTableModel->editInfo('fa_member_signout',"`member_id` = '{$id}'",array('member_phone'=>$zxInfo['member_phone'].'11'));
        }
        //解除设备限制
        $Common = New Common();
        $bfjdsbfjsb = $Common->getConfigValue('bfjdsbfjsb');
        if(!empty($bfjdsbfjsb) && !empty($memberInfo['me_cid'])){
            $bfjdsbfjsbArr = explode('#',$bfjdsbfjsb);
            foreach ($bfjdsbfjsbArr as $k=>$v){
                if($v == $memberInfo['me_cid']){
                    unset($bfjdsbfjsbArr[$k]);
                    break;
                }
            }
            $bfjdsbfjsb_new = '';
            if(!empty($bfjdsbfjsbArr)){
                $bfjdsbfjsb_new = implode('#',$bfjdsbfjsbArr);
            }
            $IndexTableModel->editInfo('fa_config',array('config_key'=>'bfjdsbfjsb'),array('config_value'=>$bfjdsbfjsb_new));
        }

        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('解除限制成功', URL_RELOAD);
    }


    //强制注销用户
    public function qzzxmember($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:qzzxmember'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }

        Db::startTrans();
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',array('member_id'=>$id),'*');
        if(empty($memberInfo)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户信息查询失败',URL_CLOSE_REFRESH);
        }
        $oldPhone = $memberInfo['me_phone'];
        $signoutInfo = $IndexTableModel->getFind('fa_member_signout',array('member_id'=>$id),'id');
        if(!empty($signoutInfo)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('此用户已经注销过了',URL_CLOSE_REFRESH);
        }
        $randint = rand(10,99).rand(100,999).rand(1,9);
        $data = array();
        if(!empty($memberInfo['me_phone'])){
            $data['me_phone'] = $memberInfo['me_phone'].'zx'.$randint;
        }
        if(!empty($memberInfo['me_wx_openid'])){
            $data['me_wx_openid'] = $memberInfo['me_wx_openid'].'zx'.$randint;
        }
        if(!empty($memberInfo['me_qq_openid'])){
            $data['me_qq_openid'] = $memberInfo['me_qq_openid'].'zx'.$randint;
        }
        if(!empty($memberInfo['me_wb_openid'])){
            $data['me_wb_openid'] = $memberInfo['me_wb_openid'].'zx'.$randint;
        }
        if(!empty($memberInfo['me_dy_openid'])){
            $data['me_dy_openid'] = $memberInfo['me_dy_openid'].'zx'.$randint;
        }
        if(!empty($memberInfo['me_ks_openid'])){
            $data['me_wx_openid'] = $memberInfo['me_ks_openid'].'zx'.$randint;
        }
//        if(!empty($memberInfo['me_nick_name'])){
//            $data['me_nick_name'] = $memberInfo['me_nick_name'].'zx'.$randint;
//        }
        if(!empty($memberInfo['me_realname'])){
            $data['me_realname'] = $memberInfo['me_realname'].'zx'.$randint;
        }
        if(!empty($memberInfo['me_realidcard'])){
            $data['me_realidcard'] = $memberInfo['me_realidcard'].'zx'.$randint;
        }
        $data['me_token'] = '';
        $data['me_zx'] = 1;
        $data['me_xn_zx'] = 1;
//        $data['me_cid'] = '';
        $data['me_status'] = 2;
        $data['me_status_time'] = -1;
        $data['me_zhuxiao'] = 1;
        $res = $IndexTableModel->editInfo('fa_member',array('member_id'=>$id),$data);
        if(empty($res)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('注销失败',URL_CLOSE_REFRESH);
        }
        $logoutRes = $IndexTableModel->addInfo('fa_member_signout',array('member_id'=>$id,'member_phone'=>$oldPhone,'add_time'=>time()));
        if(empty($logoutRes)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('注销记录添加失败',URL_CLOSE_REFRESH);
        }

        $Common = New Common();
        $bfjdsbfjsb = $Common->getConfigValue('bfjdsbfjsb');
        if(!empty($memberInfo['me_cid'])){
            $newbfjdsbfjsb = trim($bfjdsbfjsb,'#').'#'.$memberInfo['me_cid'];
            $newbfjdsbfjsb = trim($newbfjdsbfjsb,'#');
            $IndexTableModel->editInfo('fa_config',"`config_key` = 'bfjdsbfjsb'",['config_value'=>$newbfjdsbfjsb]);
        }

        $data = array();
        $data['user_id'] = $this->uid;
        $data['type'] = 10;
        $data['member_id'] = $memberInfo['member_id'];
        $data['d_member_id'] = 0;
        $data['content'] = '强制注销【'.$memberInfo['member_id'].'】用户';
        $data['add_time'] = time();
        $logRes = $IndexTableModel->addInfo('fa_user_operate_log',$data);
        if(empty($logRes)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('管理端操作日志添加失败',URL_CLOSE_REFRESH);
        }
        Db::commit();
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('强制注销用户成功', URL_RELOAD);
    }


    //取消此用户公众号进入，恢复成社会人员
    public function qxgzhmember($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:qxgzhmember'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }

        Db::startTrans();
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',array('member_id'=>$id),'*');
        if(empty($memberInfo)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户信息查询失败',URL_CLOSE_REFRESH);
        }
        if($memberInfo['is_gzh_register'] == 0){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('此用户已经是社会人员',URL_CLOSE_REFRESH);
        }
        $IndexTableModel->editInfo('fa_member',array('member_id'=>$id),['is_gzh_register'=>0]);
        Db::commit();
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }

    //将此社会人员，修改成公众号人员
    public function cwgzhmember($id){
        //操作上锁
        $Redis_Lock  =  new \Redislock();
        $otc_sell_key  =  'lock:cwgzhmember'.$id;	// 定义锁标识
        $is_lock  =  $Redis_Lock->lock($otc_sell_key, 15);	// 获取锁
        //解锁失败
        if(!$is_lock){
            return admin_error('操作频繁，请稍后再试！',URL_CLOSE_REFRESH);
        }

        Db::startTrans();
        $IndexTableModel = New IndexTableModel();
        $memberInfo = $IndexTableModel->getFind('fa_member',array('member_id'=>$id),'*');
        if(empty($memberInfo)){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('用户信息查询失败',URL_CLOSE_REFRESH);
        }
        if($memberInfo['is_gzh_register'] == 1){
            Db::rollBack();
            $Redis_Lock->unlock($otc_sell_key);	//释放锁
            return admin_error('此用户已经是公众号人员',URL_CLOSE_REFRESH);
        }
        $IndexTableModel->editInfo('fa_member',array('member_id'=>$id),['is_gzh_register'=>1]);
        Db::commit();
        $Redis_Lock->unlock($otc_sell_key);	//释放锁
        return admin_success('操作成功', URL_RELOAD);
    }




}
